﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright company="Microsoft Corp." file="AzureServiceClientsFactory.cs">
//   All rights reserved. See License.txt in the project root for license information.
// </copyright>
// 
// --------------------------------------------------------------------------------------------------------------------
namespace CloudBlitz.DeploymentManager
{
    using System;

    using AzureManagement;

    public class AzureServiceClientsFactory : IAzureServiceClientsFactory
    {
        private const string ServiceManagementBaseUri = "https://management.core.windows.net/";

        private const string ServiceManagementApiVersion = "2012-08-01";

        private const string SqlManagementBaseUri = "https://management.database.windows.net:8443/";

        private const string SqlManagementApiVersion = "1.0";

        public IAzureServiceManagementClient CreateServiceManagementClient(AzureCredentials azureCredentials)
        {
            var azureServiceCredentials = new AzureServiceCredentials(
                azureCredentials.SubscriptionId, azureCredentials.CertificateThumbprint);

            return
                new AzureServiceManagementClient(
                    new AzureServiceContext(
                        azureServiceCredentials, new Uri(ServiceManagementBaseUri), ServiceManagementApiVersion));
        }

        public ISqlAzureManagementClient CreateSqlAzureManagementClient(AzureCredentials azureCredentials)
        {
            var azureServiceCredentials = new AzureServiceCredentials(
                azureCredentials.SubscriptionId, azureCredentials.CertificateThumbprint);

            return
                new SqlAzureManagementClient(
                    new AzureServiceContext(
                        azureServiceCredentials, new Uri(SqlManagementBaseUri), SqlManagementApiVersion));
        }
    }
}